﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX.BLL.Extend;
using ZX.SYS.Library;
using ZX.EHR.Library;
using ZX.Common;
using ZX.Common.Extend;
using ZX.DBModule;
using Quartz;
using Quartz.WebLib;

//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 作 者：XXC
// Email: 
// 日 期：
// 描 述：任务配置业务处理，要将信息更新到Quartz自带的表
// 版 本：1.0.0.0    
//    
//==================================================================

namespace ZX.BLL
{
    public class BSysTaskMsg : BaseBussnies
    {

        public override bool Insert(object entitys, out string msg)
        {
            bool result = base.Insert(entitys, out msg);
            SysTaskMsg sysTaskMsg = (SysTaskMsg)entitys; 
            if (result)
            {
                AddJob(sysTaskMsg);
            }
            return result;
        }

        public override bool Update(object entitys, out string msg)
        {
            bool result = base.Update(entitys, out msg);
            SysTaskMsg sysTaskMsg = (SysTaskMsg)entitys;
            if (result)
            {
                AddJob(sysTaskMsg);
            }

            return result;
        }

        public string AddJob(SysTaskMsg sysTaskMsg)
        {
            string result = string.Empty;
            string jobInfo = "{\"JobName\":\"" + sysTaskMsg.JobName + "\",\"JobGroupName\":\"" + sysTaskMsg.GroupName + "\",\"JobType\":\"" + sysTaskMsg.JobType + "\",\"JobDes\":\"" + sysTaskMsg.Notes + "\",";
            string triggerName = "\"TriggerName\":[" + "\"" + sysTaskMsg.TriggerName + "\"]";
            string triggerGroupName = "\"TriggerGroupName\":[" + "\"" + sysTaskMsg.GroupName + "\"]";
            string triggerCron = "\"TriggerCron\":[" + "\"" + sysTaskMsg.CronExp + "\"]";
            string triggerDes = "\"TriggerDes\":[" + "\"" + sysTaskMsg.taskPlan + "\"]";
            jobInfo += triggerName + "," + triggerGroupName + "," + triggerCron + "," + triggerDes;
            jobInfo += "}";
            try
            {
                result=QuartzDataHandler.GetInstance().AddJob(jobInfo);
            }
            catch { }
            return result;
        }

    }
}
